<?php
require_once 'Service/Condition.php';

/**
 * Field appears in values list.
 *
 * @author baziak
 */
class Service_Condition_ZendDb_InValues extends Service_Condition
{
    protected $_operator = 'IN';

    public function __toString()
    {
        $db = $this->getDataSource()->getAdapter();

        $values = $this->_params['value'];

        if (is_array($values) && count($values)) {
            $ids = '(';
            foreach ($values as $item) {
                $ids .= $db->quote($item) . ',';
            }

            $ids[strlen($ids) - 1] = ')';
        } else {
            $ids = '('.$db->quote($values).')';
        }

        $field = $db->quoteIdentifier($this->_params['field']);

        return $field .' '. $this->_operator .' '. $ids;
    }
}
